package com.king.modules.monitor.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.king.common.annotation.Log;
import com.king.common.enums.BusinessType;
import com.king.common.utils.poi.ExcelUtil;
import com.king.framework.base.controller.YySuperController;
import com.king.framework.base.domain.vo.AjaxResult;
import com.king.modules.monitor.domain.SysOperLogEntity;
import com.king.modules.monitor.service.SysOperLogService;

/**
 * 操作日志记录
 * 
 * @author king
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends YySuperController<SysOperLogEntity> {
	
	@Autowired
	private SysOperLogService operLogService;


	@Log(title = "操作日志", businessType = BusinessType.EXPORT)
	@PreAuthorize("@sps.hasAuthority('monitor:operlog:export')")
	@PostMapping("/export")
	public void export(HttpServletResponse response, SysOperLogEntity operLog) {
		List<SysOperLogEntity> list = operLogService.selectOperLogList(operLog);
		ExcelUtil<SysOperLogEntity> util = new ExcelUtil<SysOperLogEntity>(SysOperLogEntity.class);
		util.exportExcel(response, list, "操作日志");
	}

	@Log(title = "操作日志", businessType = BusinessType.DELETE)
	@PreAuthorize("@sps.hasAuthority('monitor:operlog:del')")
	@DeleteMapping("/{operIds}")
	public AjaxResult remove(@PathVariable Long[] operIds) {
		return toAjax(operLogService.deleteOperLogByIds(operIds));
	}

	@Log(title = "操作日志", businessType = BusinessType.CLEAN)
	@PreAuthorize("@sps.hasAuthority('monitor:operlog:del')")
	@DeleteMapping("/clean")
	public AjaxResult clean() {
		operLogService.cleanOperLog();
		return success();
	}
}
